function quickSort(arr, start, end) {
    let key = arr[start]
    let head = start, tail = end
    while(head < tail) {
        while(head < tail && arr[tail] >= key) {
            tail--
        }
        arr[head] = arr[tail]
        while(head < tail && arr[head] <= key) {
            head++
        }
        arr[tail] = arr[head]
    }
    arr[head] = key
    if(head > start) {
        quickSort(arr, start, head - 1)
    }
    if(head < end) {
        quickSort(arr, head + 1,  end)
    }
}
let arr = [9, 4, 6, 2, 1, 1, 8]
quickSort(arr, 0, arr.length - 1)
console.log(arr);